package br.estacio.contatos.client.ui;

import br.estacio.contatos.client.ClientFactory;
import br.estacio.contatos.client.place.EditarContatoPlace;
import br.estacio.contatos.client.place.ListarContatoPlace;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

public class Shell extends ViewInternacionalizada implements AcceptsOneWidget {

	private static ShellUiBinder uiBinder = GWT.create(ShellUiBinder.class);
	
	@UiField
	MenuItem novoMenuItem;
	
	@UiField
	MenuItem listarMenuItem;
	
	@UiField
	SimplePanel contentPanel;

	private ClientFactory clientFactory;

	interface ShellUiBinder extends UiBinder<Widget, Shell> {
	}

	public Shell(final ClientFactory clientFactory) {
		super(clientFactory.getContatosConstants());
		this.clientFactory = clientFactory;
		initWidget(uiBinder.createAndBindUi(this));
		inicializarComandosMenu();
	}

	private void inicializarComandosMenu() {
		novoMenuItem.setCommand(new Command() {
			@Override
			public void execute() {
				clientFactory.getPlaceController().goTo(new EditarContatoPlace("new"));
			}
		});
		listarMenuItem.setCommand(new Command() {
			@Override
			public void execute() {
				clientFactory.getPlaceController().goTo(new ListarContatoPlace());
			}
		});
	}

	@Override
	public void setWidget(IsWidget w) {
		contentPanel.setWidget(w);
	}


}
